package com.liuning.controller;

import com.liuning.common.lang.Result;
import com.liuning.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class TestController extends BaseController{

    @Autowired
    SysUserService sysUserService;

    @Autowired
    BCryptPasswordEncoder bCryptPasswordEncoder;

    @PreAuthorize("hasRole('admin')")
    @GetMapping("/test")
    public Result test(){
        return Result.succ(sysUserService.list());
    }

    @PreAuthorize("hasAuthority('sys:user:list')")
    @GetMapping("/test/pass")
    public Result pass() {
        //加密后的密码
        String password = bCryptPasswordEncoder.encode("123456");
        //与加密后的密码进行匹配
        boolean matches = bCryptPasswordEncoder.matches("123456", password);
        System.out.println("结果是："+matches);
        return Result.succ(password);
    }
}
